package controller;

import com.github.pagehelper.PageInfo;
import domain.ErrorLog;
import domain.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import service.ErrorLogService;
import service.LogService;

@Controller
@RequestMapping("/errorLog")
public class ErrorLogController {
    @Autowired
    private ErrorLogService errorLogService;

    @RequestMapping("/all")
    public ModelAndView all(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "5") int pageSize){
        ModelAndView modelAndView = new ModelAndView();
        PageInfo<ErrorLog> errorLogAll = errorLogService.findErrorLogAll(pageNum, pageSize);
        modelAndView.getModel().put("errorlogs",errorLogAll);
        modelAndView.setViewName("errorlog_all");
        return modelAndView;
    }

    @RequestMapping("/desc")
    public ModelAndView desc(int id){
        ModelAndView modelAndView = new ModelAndView();
        ErrorLog errorLogById = errorLogService.findErrorLogById(id);
        modelAndView.getModel().put("errorlog",errorLogById);
        modelAndView.setViewName("errorlog_desc");
        return modelAndView;
    }
}
